package com.example.bestudentsystem.demos.web.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bestudentsystem.demos.web.mapper.AdminMapper;
import com.example.bestudentsystem.demos.web.mapper.CourseMapper;
import com.example.bestudentsystem.demos.web.mapper.StudentMapper;
import com.example.bestudentsystem.demos.web.mapper.TeacherMapper;
import com.example.bestudentsystem.demos.web.pojo.Student;
import com.example.bestudentsystem.demos.web.vo.HistoryVo;
import com.example.bestudentsystem.demos.web.vo.SCVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class studentController {
    @Autowired
    AdminMapper adminMapper;
    @Autowired
    StudentMapper studentMapper;
    @Autowired
    TeacherMapper teacherMapper;
    @Autowired
    CourseMapper courseMapper;

    @GetMapping("/getMySData")
    public Student getStudent(@RequestParam String id) {
        return studentMapper.selectById(id);
    }
    @GetMapping("/getMySC")
    public List<SCVo> getMySC(@RequestParam String id) {
        return studentMapper.getStudentSCBySno(id);
    }
    @GetMapping("/getCourseHistory")
    public List<HistoryVo> getCourseHistory(@RequestParam String id) {
        return courseMapper.getCourseHistory(id);
    }
    @PutMapping("/updateMySData")
    public void updateMySData(@RequestBody Student student) {
        studentMapper.updateById(student);
    }
    //分页获取学生课程
    @GetMapping("/getMySCByPage")
    public IPage<SCVo> getMySCByPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize,
                                     @RequestParam("sno") String sno) {
        IPage<SCVo> iPage = new Page<>(pageNum,pageSize);
        return studentMapper.getStudentCourse(iPage,sno);
    }
}